/***********************************************************************
	filename: 	DaterLinktoSQL.h
	created:	15/4/2012
	author:		4Ys
	
	purpose:	Defines a class of connection between C++ and mySQL
*************************************************************************/
#ifndef _DaterLinktoSQL_h_
#define _DaterLinktoSQL_h_

#include <stdio.h>
#include <string>
#include <afxsock.h>
#include <mysql.h>

#pragma comment(lib, "libmysql.lib")

namespace Dater
{
	class LinktoSQL
	{
	public:	
		/*!
			\brief
				Construct class DaterLinktoSQL.
		*/
		LinktoSQL();
		
		/*!
			\brief
				Destruct class DaterLinktoSQL.
		*/
		~LinktoSQL();
		
		/*!
		 \brief
			 A processing function to initialize and link the database.

		 \param host
		     - a char* which is the host name of the database.

		 \param port
		     - a char* which is the port of the database.
			 - usually 3306.
			 
		 \param Db
		     - a char* which is the name of the database.

		 \param user
		     - a char* which is the name of the user of the database.

		 \param passwd
		     - a char* which is the password of the database.

		 \param charset
		     - a char* which supplies Chineses characters.

		 \param Msg
		     - a char* which shows the message of program.

		 \return
			 - 1 : successfully connect to database.
			 - 0 : something error.
		*/
		int ConnMySQL(char* host, char* port, char* Db, char* user, char* passwd, char* charset, char* Msg);
		
		/*!
		 \brief
			 A processing function to look up the information in database.

		 \param SQL
		     - a char* which operates database.

		 \param Cnum
		     - an integer which is a number of rows.
			 
		 \param Msg
		     - a char* which shows the message of program.

		 \return
			 result of the information which user looks up.
		*/
		std::string SelectData(char* SQL, int Cnum, char* Msg, char rowDelimiter, char columnDelimiter);
		
		/*!
		 \brief
			 A processing function to insert the information in database.

		 \param SQL
		     - a char* which operates database.

		 \param Msg
		     - a char* which shows the message of program.
			 
		 \return
			 - 1 : successfully insert into database.
			 - 0 : something error.
		*/
		int InsertData(char* SQL, char* Msg);
		
		/*!
		 \brief
			 A processing function to update the information in database.

		 \param SQL
		     - a char* which operates database.

		 \param Msg
		     - a char* which shows the message of program.
			 
		 \return
			 - 1 : successfully update database.
			 - 0 : something error.
		*/
		int UpdateData(char* SQL, char* Msg);
		
		/*!
		 \brief
			 A processing function to delete information from database.

		 \param SQL
		     - a char* which operates database.

		 \param Msg
		     - a char* which shows the message of program.
			 
		 \return
			 - 1 : successfully delete information from database.
			 - 0 : something error.
		*/
		int DeleteData(char* SQL, char* Msg);
		
		/*!
		 \brief
			 A processing function to close connection between C++ and database.
			 
		 \return
			 Nothing.
		*/
		void CloseMySQLConn();
		
		/*!
		 a char* to describe error message within process.
		*/
		char* Msg;
	private:
		/*!
			a realization of mysql to set link between c++ and mySQL.
		*/
		MYSQL mysql;

	};

}
#endif